package com.parking.status.sync.netty.server;

import com.parking.status.sync.netty.entity.ContentBase;
import com.parking.status.sync.netty.entity.MessageBody;
import com.parking.status.sync.netty.util.ContentFactory;
import com.parking.status.sync.repository.ParkingLotRepository;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by Administrator on 2015/9/17.
 */
public class ContentDecoder extends MessageToMessageDecoder<MessageBody> {

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, MessageBody messageBody, List<Object> out) throws Exception {
        int contentType = messageBody.getContentType();
        byte[] contentBytes = messageBody.getContent();
        ContentBase content = ContentFactory.getContent(contentType, contentBytes);
        //保存到数据库
        content.save();
    }
}
